
var zNodes =[
	{ id:1, pId:0, name:"人员管理",  open:true,click:false},
	{ id:11, pId:1, name:"部门管理",title:"department"},
	{ id:12, pId:1, name:"员工管理",title:"employer"},
	{ id:13, pId:1, name:"职务管理",title:"position"},
	{ id:2, pId:0, name:"理念",  open:false,click:false},
	{ id:21, pId:2, name:"理念操作",title:"idea"},
	{ id:3, pId:0, name:"捐助",  open:false,click:false},
	{ id:31, pId:3, name:"捐助操作",title:"pay"},
	{ id:4, pId:0, name:"下载",  open:false,click:false},
	{ id:41, pId:4, name:"下载操作",title:"download"},
	{ id:5, pId:0, name:"源码教学",  open:false,click:false},
	{ id:51, pId:5, name:"源码教学操作",title:"code"},
	{ id:6, pId:0, name:"未来计划",  open:false,click:false},
	{ id:61, pId:6, name:"未来计划操作",title:"plan"},
	{ id:7, pId:0, name:"留言管理",  open:false,click:false},
	{ id:71, pId:7, name:"留言操作",title:"message"},
	{ id:8, pId:0, name:"其他",  open:false,click:false},
	{ id:81, pId:8, name:"友情链接",title:"links"},
	{ id:82, pId:8, name:"通知公告",title:"announcement"},
	{ id:83, pId:8, name:"统计",title:"count"}
	
];


function beforeClick(treeId, treeNode, clickFlag) {
	return (treeNode.click != false);
}
function onClick(event, treeId, treeNode, clickFlag) {
	addPanel(treeNode.name,treeNode.title);
}


function addPanel(name,title){
	var location = '';
//	var isSuperAdmin = $("#isSuperAdmin").val();
	if(title == 'department'){
		location = "department/list.jsp";
	}
	if(title == 'employer'){
		location = "employer.jsp";
	}
	if(title == 'position') {
		location = "position.jsp";
	}
	if(title == 'idea'){
		location = "/admin/modeinfo/rendPage?type=admin&modelId=1";
	}
	if(title == 'pay'){
		location = "/admin/modeinfo/rendPage?type=admin&modelId=2";
	}
	if(title == 'download'){
		location = "/admin/modeinfo/rendPage?type=admin&modelId=3";
	}
	if(title == 'code'){
		location = "code.jsp";
	}
	if(title == 'plan'){
		location = "/admin/modeinfo/rendPage?type=admin&modelId=4";
	}
	if(title == 'message'){
		location = "demo.jsp";
	}
	if(title == 'links'){
		location = "demo.jsp";
	}
	if(title == 'announcement'){
		location = "demo.jsp";
	}
	if(title == 'count'){
		location = "demo.jsp";
	}
	
	var contents = '<iframe scrolling="no" frameborder="0"  src="'+location+'" style="width:100%;height:100%;"></iframe>';  
	 if ($('#tabs').tabs('exists', name)){
	        $('#tabs').tabs('select', name);
	 } else {
		 $('#tabs').tabs('add',{
		        title: name,
		        content: contents,
		        closable: true
		    });
	 }
}
 
 function tabsMenus(){
	//绑定tabs的右键菜单
		$("#tabs").tabs({
		  onContextMenu:function(e,title){
		    e.preventDefault();
		    $('#tabsMenu').menu('show', {  
		      left: e.pageX,  
		      top: e.pageY  
		    }).data("tabTitle",title);
		  }
		}); 
		//实例化menu的onClick事件
		$("#tabsMenu").menu({
			onClick : function (item) {
				CloseTab(this, item.name);
			}
		});
 }


//几个关闭事件的实现
function CloseTab(menu, type) {
	var curTabTitle = $(menu).data("tabTitle");
	var tabs = $("#tabs");
	
	if (type === "close") {
		tabs.tabs("close", curTabTitle);
		return;
	}
	
	var allTabs = tabs.tabs("tabs");
	var closeTabsTitle = [];
	
	$.each(allTabs, function () {
		var opt = $(this).panel("options");
		if (opt.closable && opt.title != curTabTitle && type === "Other") {
			closeTabsTitle.push(opt.title);
		} else if (opt.closable && type === "All") {
			closeTabsTitle.push(opt.title);
		}
	});
	
	for (var i = 0; i < closeTabsTitle.length; i++) {
		tabs.tabs("close", closeTabsTitle[i]);
	}
} 

//已dialog的方式弹出窗口
function add(title,addurl,gname,width,height) {
	if(!isNull(gname)) {
		var _width = 500;
		var _height = 400;
		if(!isNull(width)) {
			_width = width;
		}
		if(!isNull(height)){
			_height = height;
		}
		$('#' + gname).dialog({
			title: title,
			width: _width,
			height: _height,
			closed: true,
			cache: false,
			href: addurl,
			modal: true
			});
	}
}

//判断某字段是否为空
function isNull(arg1)
{
	return !arg1 && arg1!==0 && typeof arg1!=="boolean"?true:false;
}

var url;

//图片上传预览    IE是用了滤镜。
/**
 * file:this
 * showDiv:展示预览图片的div
 * imgId:预览图片的ID
 * MAXWIDTH：预览图片的宽度
 * MAXHEIGHT：预览图片的高度
 * picUrl:要清除文本框的id
 * */
function previewImage(file,divId,imgId,picUrl) {
	//清除picUrl
	$('#'+picUrl).val('');
	var MAXWIDTH = 260;
	var MAXHEIGHT = 180;
	var div = document.getElementById(divId);
	if (file.files && file.files[0]) {
		div.innerHTML = '<label>预览</label><img id=' + imgId + '>';
		var img = document.getElementById(imgId);
		img.onload = function() {
			var rect = clacImgZoomParam(MAXWIDTH, MAXHEIGHT,
					img.offsetWidth, img.offsetHeight);
			img.width = rect.width;
			img.height = rect.height;
			//              img.style.marginLeft = rect.left+'px';
			img.style.marginTop = rect.top + 'px';
		};
		var reader = new FileReader();
		reader.onload = function(evt) {
			img.src = evt.target.result;
		};
		reader.readAsDataURL(file.files[0]);
	} else //兼容IE
	{
		var sFilter = 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src="';
		file.select();
		var src = document.selection.createRange().text;
		div.innerHTML = '<label>预览</label><img id=imghead>';
		var img = document.getElementById('imghead');
		img.filters.item('DXImageTransform.Microsoft.AlphaImageLoader').src = src;
		var rect = clacImgZoomParam(MAXWIDTH, MAXHEIGHT, img.offsetWidth,
				img.offsetHeight);
		status = ('rect:' + rect.top + ',' + rect.left + ',' + rect.width
				+ ',' + rect.height);
		div.innerHTML = "<div id=divhead style='width:"+rect.width+"px;height:"+rect.height+"px;margin-top:"+rect.top+"px;"+sFilter+src+"\"'></div>";
	}
}
function clacImgZoomParam(maxWidth, maxHeight, width, height) {
	var param = {
		top : 0,
		left : 0,
		width : width,
		height : height
	};
	if (width > maxWidth || height > maxHeight) {
		rateWidth = width / maxWidth;
		rateHeight = height / maxHeight;

		if (rateWidth > rateHeight) {
			param.width = maxWidth;
			param.height = Math.round(height / rateWidth);
		} else {
			param.width = Math.round(width / rateHeight);
			param.height = maxHeight;
		}
	}

	param.left = Math.round((maxWidth - param.width) / 2);
	param.top = Math.round((maxHeight - param.height) / 2);
	return param;
}